package com.cancer.biz.base.service;

import java.util.List;
import java.util.Properties;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cancer.biz.base.entity.SysParam;
import com.cancer.biz.base.entity.query.SysParamQuery;
import com.cancer.biz.base.mapper.SysParamDao;
@Service
public class SysParamServiceImpl implements SysParamService {
	@Autowired
	private SysParamDao sysParamDao;
	
	@Override
	public Properties queryParamsAsProperties(String group, String key, Boolean enable) {
		Properties prop = new Properties();
		SysParamQuery query = new SysParamQuery();
		SysParamQuery.Criteria criteria = query.createCriteria();

		if (group != null) {
			criteria.andGroupEqualTo(group);
		}

		if (key != null && key.length() > 0) {
			criteria.andParamKeyEqualTo(key);
		}

		if (enable != null) {
			criteria.andEnableEqualTo(enable);
		}

		query.setOrderByClause("param_id desc");
		List<SysParam> params = sysParamDao.selectByExample(query);

		if (params != null) {
			for (SysParam p : params) {
				prop.setProperty(p.getParamKey(), p.getParamValue());
			}
		}

		return prop;
	}

}
